<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<html>
	<head>
		<title>释放单-选合格证</title>
		<script src="${contextPath}/scripts/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
		<script type="text/javascript">
		function jumpPage(page) {
			var searchForm = document.searchForm;
			
			searchForm.action ="<s:property value='contextPath'/>/cm/choose.do?currentPage=" + page;;
			searchForm.submit();
		}
		
		//根据值从删除中删除指定元素
		Array.prototype.removeByValue = function(val) {
			for(var i=0; i<this.length; i++) {        
				if(this[i] == val) {            
					this.splice(i, 1);            
				break;        
				}    
				}
		};
		
		//每一个checkbox的点击事件
		function dock(el){
			var data_ids=$("#ids").val();
			var data_vals=$("#vals").val();
			var data_indexA=$("#indexA").val();
			var price=0.0;
			if($("#price").val())
				price=parseFloat($("#price").val());	
			var id_ary;var val_ary;
			if(data_ids.length>0)
				id_ary=data_ids.split(",");
			else
				id_ary=new Array();
			if(data_vals.length>0)
				val_ary=data_vals.split(",");
			else
				val_ary=new Array();
			if(el.checked){
				id_ary.push($(el).attr('id'));
				val_ary.push($(el).val());
				data_indexA = Number(data_indexA) + Number(1);
				var tmp = $("#"+$(el).attr('id')+"_supplyPrice").val();
				if(tmp){
					price+=	parseFloat(tmp);
				}
			}else{
				id_ary.removeByValue($(el).attr('id'));
				val_ary.removeByValue($(el).val());
				data_indexA = Number(data_indexA) - Number(1);
				var tmp = $("#"+$(el).attr('id')+"_supplyPrice").val();
				if(tmp){
					price -=	parseFloat(tmp);
				}
			}
			data_ids='';data_vals='';
			for(var i=0;i<id_ary.length;i++){
				if(i!=id_ary.length-1){
					data_ids+=id_ary[i]+',';
					data_vals+=val_ary[i]+',';
				}else{
					data_ids+=id_ary[i];
					data_vals+=val_ary[i];
				}
			}
			$("#ids").val(data_ids);
			$("#vals").val(data_vals);
			$("#price").val(price);
			$("#indexA").val(data_indexA);
		}
		//初始化
		$(document).ready(function(){
			var pre=$("#ids").val();
			if(pre!=null&&pre!=''){
				var ary=pre.split(",");
				var tmp='';
				if(ary!=null&&ary.length>0){
					for(var i=0;i<ary.length;i++){
						tmp=ary[i];
						tmp=$.trim(tmp);
						$("#"+tmp).attr('checked',true);
					}	
				}
			}
			//全选
			$("#check_all").click(function(){  
				$("input[name='mid']").each(function(){
					if($(this).is(':checked')!=$("#check_all").is(':checked')){
						$(this).attr('checked', $("#check_all").is(':checked'));
						
						dock(this);
					}
				});
			});
			
			//确定
			$("#btn").click(function(){
				   $("#sel_cf_ids", opener.document).val($("#ids").val());
				   $("#sel_cf_vals", opener.document).val($("#vals").val());
				   $("#supplyPrice", opener.document).text($("#price").val());
				   $("#indexA", opener.document).val($("#indexA").val());
				   window.close();
			});
			
			});
		</script>
	</head>
	<body>
      <form name="searchForm" id="searchForm" method="post" action="choose.do">
	      <table width="100%" border="0" cellspacing="-1" cellpadding="-1">
	        <tr><td>
	        	<input type="hidden" name="search.state" value="<s:property value='search.state'/>" />
		        <input type="hidden" name="search.financial.id" value="<s:property value='search.financial.id'/>" />
				<input type="hidden" name="search.shop.id" value="<s:property value='search.shop.id'/>" />
				<input type="hidden" name="search.brand.id" value="<s:property value='search.brand.id'/>" />
				<input type="hidden" name="search.releaseId" value="<s:property value='search.releaseId'/>" />
				<input type="hidden" name="search.type" value="<s:property value='search.type'/>"/>
				<input type="hidden" id="ids" name="ids" value="<s:property value='ids'/>" />
				<input type="hidden" id="vals" name="vals" value="<s:property value='vals'/>"/>
				<input type="hidden" id="price" name="price" value="<s:property value='price'/>"/>
				<input type="hidden" id="indexA" name="indexA" value="<s:property value='indexA'/>"/>
	        </td></tr>
	      </table>
      
      
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
		  <tr>
		    <td height="25" align="left"><font color="#0066CC"><strong>合格证列表：</strong></font></td>
		    <td height="25" align="right" style="padding-right: 40px">
            </td>
		  </tr>
		  <tr>
		    <td height="25" align="left">黄色为变更运输地的合格</td>
		    <td height="25" align="right" style="padding-right: 40px">
			   车架号: <input name="search.chassis" value="<s:property value='search.chassis'/> " />
			    <input type="submit" value=""  class="btn_query"/>
            </td>
		  </tr>
		</table>
		</form>
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
	  <tr> 
	  	<td width="3%" class="top-td-width-bg"><input type="checkbox" id="check_all" name="check_all" /></td>
	    <td width="5%" class="top-td-width-bg">序号</td>
	    <td width="9%" class="top-td-width-bg">店号</td>
	    <td width="9%" class="top-td-width-bg">店名</td>
	    <td width="9%" class="top-td-width-bg">车型</td>
	    <td width="9%" class="top-td-width-bg">合格证号</td>
	    <td width="9%" class="top-td-width-bg">车架号</td>
	    <td width="9%" class="top-td-width-bg">供货价</td>
	    <td width="9%" class="top-td-width-bg">订单号</td>
	    <td width="9%" class="top-td-width-bg">入库日期</td>
	    <td width="8%" class="top-td-width-bg">状态</td>
	    <td width="12%" class="top-td-width-bg">是否已存在释放单</td>
	  </tr>
	 <s:iterator value="page.result" status="st" >
	 <s:if test="change&&search.type=='release'">
		<tr height="26" align="center" bgcolor="#F7F709">
	</s:if>
	<s:else>
		<tr height="26" align="center" bgcolor="#FFFFFF">
	</s:else>
			<td>
			<s:if test="release==null||release.id==search.releaseId">
				<input name="mid" type="checkbox" id="<s:property value='id'/>" value="<s:property value='chassis'/>" onclick="dock(this)"/>
			</s:if>
			</td>
			<td><s:property value="#st.index+1"/></td>
		    <td><s:property value="shop.shopMark"/></td>
		    <td><s:property value="shop.shopName"/></td>
		    <td><s:property value="motorcycleType"/></td>
		    <td><s:property value="certificationNum"/></td>
		    <td><s:property value="chassis"/></td>
		    <td><s:property value="formatAmount(supplyPrice)"/><input id="<s:property value='id'/>_supplyPrice" type="hidden" value="<s:property value="supplyPrice"/>"/></td>
		    <td><s:property value="orderNumber"/></td>
		    <td><s:date name="warehouseDate" format="yyyy-MM-dd"/></td>
		    <td><s:property value="state.name" /></td>
		    <td>
		    	<s:if test="release!=null&&release.id!=search.releaseId">
		    		已存在释放单<s:property value="release.applyNum" />
		    	</s:if><s:else>否</s:else>
		    </td>
		</tr>
	</s:iterator>
	<tr bgcolor="#F9FCEF"> 
	 <td height="36" colspan="12" align="center">
			<%@ include file="/WEB-INF/view/common/pagination.jsp"%>
	 </td>
	</tr>
	<tr> 
	 <td height="26" colspan="12" align="center" bgcolor="#FFFFFF">
			<input id='btn' type="button" value='确定'  border="0" class="np" style="height: 30px;width: 80px"/>
	 </td>
	</tr>
	</table>
	</body>
</html>